package org.uned.agonzalo16.bitacora.service.article;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.uned.agonzalo16.bitacora.domain.Article;

public class ArticleCount implements Comparable<ArticleCount> {
	private final Article article;
	private Integer count;

	public ArticleCount(Article article) {
		this.article = article;
		this.count = 1;
	}

	public Article getArticle() {
		return article;
	}

	public void addComment() {
		this.count++;
	}

	@Override
	public int compareTo(ArticleCount o) {
		return o.count - count;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof ArticleCount)) {
			return false;
		} else if (this == obj) {
			return true;
		} else {
			ArticleCount that = (ArticleCount) obj;
			return this.article.getId().equals(that.article.getId());
		}
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(count).append(article.getId()).build();
	}

}
